
import request from '@/utils/request'
// 获取推荐文章
export const getArticlesAPI = ({ channel_id, timestamp = new Date() }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id,
      timestamp
    }
  })
}

// 提交不喜欢的文章
export const dislikeArticleAPI = (artId) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: artId
    }
  })
}

// 举报文章
export const reportActicleAPI = ({ artId, type }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: artId,
      type,
      remark: '其他问题'
    }
  })
}

// 文章详情
export const articleDetailAPI = ({ artId }) => {
  return request({
    url: `/v1_0/articles/${artId}`
  })
}

// 关注作者
export const followedUserAPI = (autId) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: autId
    }
  })
}

// 取消关注作者
export const unFollowedUserAPI = (autId) => {
  return request({
    url: `/v1_0/user/followings/${autId}`,
    method: 'DELETE'
  })
}

// 点赞文章
export const likeArticleAPI = (artId) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: artId
    }
  })
}

// 取消点赞文章
export const unLikeArticleAPI = (artId) => {
  return request({
    url: `/v1_0/article/likings/${artId}`,
    method: 'DELETE'
  })
}

// 获取文章评论
export const getArticleCommentsAPI = ({ commentId, offset = null, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: commentId,
      offset,
      limit
    }
  })
}

// 对文章评论
export const sendCommentAPI = ({ target, content, artId = null }) => {
  const obj = {
    target: target, // 评论或者文章的id
    content: content
  }
  if (artId !== null) {
    obj.art_id = artId
  }
  // 如果外面传入artId，证明是要对评论进行回复，需要第三个参数
  // 对评论进行回复，我才需要添加文章ID字段和值
  // 如果target是评论的ID(对评论进行回复)，才需要携带文章ID，如果target是文章的ID(无需此参数)
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: obj
  })
}
// 点赞红心评论
export const likeCommentAPI = (commentId) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: commentId
    }
  })
}
// 取消点赞红心评论
export const unLikeCommentAPI = (commentId) => {
  return request({
    url: `/v1_0/comment/likings/${commentId}`,
    method: 'DELETE'
  })
}
